<template>
  <div>
    <el-table :data="tableData" style="width: 100%">
      <el-table-column label="试题id" width="180">
        <template slot-scope="scope">
          <i class="el-icon-id"></i>
          <span style="margin-left: 10px">{{
            scope.row.questions_type_id
          }}</span>
        </template>
      </el-table-column>
      <el-table-column label="试题类型" width="180">
        <template slot-scope="scope">
          <el-popover trigger="hover" placement="top">
            <p>试题类型: {{ scope.row.questions_type_text }}</p>
            <p>试题序号: {{ scope.row.questions_type_id }}</p>
            <div slot="reference" class="name-wrapper">
              <el-tag size="medium">{{ scope.row.questions_type_text }}</el-tag>
            </div>
          </el-popover>
        </template>
      </el-table-column>
      <el-table-column label="操作">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="primary"
            @click="dialogFormVisible = true"
            >编辑</el-button
          >
          <el-button
            size="mini"
            type="danger"
            @click="handleDelete(scope.$index, scope.row)"
            >删除</el-button
          >
        </template>
      </el-table-column>
    </el-table>

    <el-dialog title="修改试题类型" :visible.sync="dialogFormVisible">
      <el-form :model="form">
        <el-form-item label="试题id" :label-width="formLabelWidth">
          <el-input v-model="form.name" autocomplete="off"></el-input>
        </el-form-item>
        <el-form-item label="试题类型" :label-width="formLabelWidth">
          <el-select v-model="form.region" placeholder="请选择活动区域">
            <el-option label="单选题" value="danxuan"></el-option>
            <el-option label="多选题" value="duoxuan"></el-option>
            <el-option label="简答题" value="duoxuan"></el-option>
            <el-option label="应用题" value="duoxuan"></el-option>
          </el-select>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="dialogFormVisible = false">取 消</el-button>
        <el-button type="primary" @click="dialogFormVisible = false"
          >确 定</el-button
        >
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { getClassify, delClassify } from "../../../api/classify";
export default {
  data() {
    return {
      dialogFormVisible: false,
      form: {
        name: "",
        region: "",
      },
      formLabelWidth: "120px",
      tableData: [],
    };
  },
  methods: {
    handleDelete(index, row) {
      delClassify({
        id: row.questions_type_id,
      }).then((res) => {
        if (res.data.msg === "删除成功") {
          this.tableData.splice(index, 1);
          this.$message({
            message: "删除成功",
            type: "success",
          });
        } else {
          this.$message({
            message: "删除失败",
            type: "error",
          });
        }
      });
    },

  },
  mounted() {
    getClassify().then((res) => {
      // console.log(res.data.data)

      this.tableData = res.data.data;
    });
  },
};
</script>

<style>
</style>